{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ed081f91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b24a4a92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "54bea616",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbf16440",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "> 1.数值\n",
    "> 1.int\n",
    "> 2.float\n",
    "> 3.complex\n",
    "\n",
    "> 2.字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "74cb281d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7bf7de24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "b = 11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "6fb0f326",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "c = 5+3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "242bbb7f",
   "metadata": {},
   "source": [
    " ##  2.字符串(string)\n",
    "  ### 1.\n",
    "  ### 2.关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a0418932",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e6f8376c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ed08b23d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'doesn\"t'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\"t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7241ece1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'doesn\"t'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn\\\"t\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7aae0cbd",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'nfu_index_page_html' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [13]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mnfu_index_page_html\u001b[49m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'nfu_index_page_html' is not defined"
     ]
    }
   ],
   "source": [
    "print(nfu_index_page_html)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98f2cfd1",
   "metadata": {},
   "source": [
    "### 2.关于字符串的方法及函数\n",
    "> 1.定义\n",
    "* 单引号：'allows embedded \"double\" quotes'\n",
    "\n",
    " * 双引号：\"allows embedded 'single' quotes\"\n",
    "\n",
    " * 三重引用： ，'''Three single quotes'''\"\"\"Three double quotes\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8e5fcb98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "title = \"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0c319a99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0] #取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "79d5ecc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1] #取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "b1550eed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "dfeb35f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6] # 取一定范围的值，称为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "624da941",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "95edb8b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广\n",
      "州\n",
      "南\n",
      "方\n",
      "学\n",
      "院\n",
      "坐\n",
      "落\n",
      "于\n",
      "广\n",
      "州\n",
      "市\n",
      "从\n",
      "化\n",
      "温\n",
      "泉\n",
      "镇\n"
     ]
    }
   ],
   "source": [
    " # 利用for循环，遍历文本信息\n",
    "for i in title:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "7158881b",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block (3803225248.py, line 4)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [42]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(i,(0,3))\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
     ]
    }
   ],
   "source": [
    " ## enumerate 枚举，既可以获取到内容 item ，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "aafc6dcd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "# 思考，如何判断一段文本中是否存在“广州”，例如文本 title 中的内容\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "c433325b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州这个词在这段文本中\n",
      "广州这个词在这段文本中\n"
     ]
    }
   ],
   "source": [
    "for i,j in enumerate(title):\n",
    "    if j == \"广\":\n",
    "        if title[i+1] == \"州\":\n",
    "          print(\"广州这个词在这段文本中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "15c6b188",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## Page59  in 检查成员对象\n",
    "\"广州\"in title\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ec67af0",
   "metadata": {},
   "source": [
    "## 总结\n",
    "> 1.\n",
    "字符串首字母转成大写，也有把字符串的大写字母转成小写。\n",
    "\n",
    "name='ds'。\n",
    "\n",
    "print(name.capitalize())\n",
    "\n",
    "name='EDSWE'。\n",
    "\n",
    "print(name.casefold())\n",
    "\n",
    "* 2字符串宽度填充，使用原有字符串+填充字符构成指定长度的新的字符串，默认是填充空格\n",
    "\n",
    "name='swhthaitun'。\n",
    "\n",
    "print(name.center(15,\"@\"))\n",
    "\n",
    "* 3统计某个字符在字符串中出现的次数，或在字符串指定区间中查找\n",
    "\n",
    "name='ssssssssgfdfghggdfgfghhhfd'print(name.count('h'))print(name.count('h'：3,18))\n",
    "\n",
    "* 4endswith判断字符串是否以某个字符串结尾的\n",
    "\n",
    "name='ssssssssgfdfghggdfgfghhhfd\n",
    "\n",
    "print(name.endswith('s'))\n",
    "\n",
    "print(name.endswith('d'))\n",
    "\n",
    "* 5index()在字符串中查找指定的字符串\n",
    "\n",
    "join()字符串连接\n",
    "\n",
    "name='fsdfsfsadeewrwe'。\n",
    "\n",
    "print(name.index('w'))\n",
    "\n",
    "name='fs'。\n",
    "\n",
    "print('*'.join(name))\n",
    "\n",
    "* 6partition分隔符将字符串进行分割元组\n",
    "\n",
    "replace把字符串中的旧字符串替换成新字符串\n",
    "\n",
    "name='fsdfsfsadeewrwe'print(name.partition(\"sad\"))print(name.replace(\"eew\"：\"1110\"))\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dec3e839",
   "metadata": {},
   "source": [
    "* 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "9458ad79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好 , Alex\n"
     ]
    }
   ],
   "source": [
    "# 字符串不可以和数字连接\n",
    "print(\"你好 \"+\", \"+\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "9127536b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "5f34a8e1",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [70]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以 用来运算\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "# 字符串不可以 用来运算\n",
    "\"3\"/\"2\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78b359c4",
   "metadata": {},
   "source": [
    "* 字符串的拆分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "36149101",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由于没有分清楚 字符串 和数值的概念导致的笑话\n",
    "width = \"16\"\n",
    "height = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "7f3cc0d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width*height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "ecd19e6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'161616161616161616'"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "472ab63b",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "c199ce23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "a0b94872",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "118765f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于广州市从化温泉镇'"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "7c9c57ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "2702d2d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化温泉镇']"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "f8853586",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"\"\"\n",
    "您好，学习通账号绑定的腾讯会议账号与目前登录的腾讯会议不一致会出现该情况，建议您登录学习通账号后打开解绑链接：https://k.chaoxing.com/app/tencent/unbind，（解绑后务必清理浏览器缓存），清除缓存后可重新登录打开试下。\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "249fdfc8",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 可以搜索停止字典，进行文本拆分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20b78e7d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
